<?php

namespace App\Services;

use Exception;
use Illuminate\Support\Facades\Log;

class HttpService
{

    static public function post($url, $data = '', $token = '', $success_callback = null, $error_callback = null)
    {
        $client = new \GuzzleHttp\Client([
            'base_uri' => $url,
            'headers' => ['Authorization' => $token],
            'verify' => false,
            'http_errors' => false,
            'synchronous' => false,
        ]);

        try {
            $res = $client->request(
                'POST',
                '',
                [
                    'json' => json_encode($data),
                    'headers' => [
                        'Content-type' => 'application/json',
                        "Accept" => "application/json"
                    ]
                ]
            );
            if ($success_callback != null)
                $success_callback($res);
            return $res;
        } catch (Exception $e) {
            if ($error_callback != null)
                $error_callback($e);
        };
    }
}
